﻿using Gateway.Common.Entity;

namespace Gateway.Domain.Entities;

/// <summary>
/// 试题
/// </summary>
public class Question : AggregateRootEntityBase
{
    /// <summary>
    /// 试题名称
    /// </summary>
    public string QuestionName { get;private set; }
    /// <summary>
    /// 试题描述
    /// </summary>
    public string QuestionDescribe { get;private set; }

    /// <summary>
    /// 测试用例
    /// </summary>
    public string QuestionCase { get;private set; }

    /// <summary>
    /// 试题对应的代码配置
    /// </summary>
    public List<QuestionLanguage> Languages { get;private set; }
    public Question()
    {

    }

    public Question(string questionName = default, string questionDescribe = default, string questionCase = default)
    {
        QuestionName = questionName;
        QuestionDescribe = questionDescribe;
        //ExamplesFileName = examplesFileName;
        //ExecFileName = execFileName;
        //Examples = examples;
        QuestionCase = questionCase;
        //ExtensionCodes = extensionCodes;
    }

    public void Update(string questionName = default, string questionDescribe = default, string questionCase = default)
    {
        QuestionName = questionName;
        QuestionDescribe = questionDescribe;
        //ExamplesFileName = examplesFileName;
        //ExecFileName = execFileName;
        //Examples = examples;
        QuestionCase = questionCase;
        //ExtensionCodes = extensionCodes;
    }
    /// <summary>
    /// 设置语言
    /// </summary>
    /// <param name="languages"></param>
    public void SetLanguages(List<QuestionLanguage> languages)
    {
        Languages ??= new List<QuestionLanguage>();
        foreach (var item in languages)
        {
            var info = Languages.FirstOrDefault(p => p.Language.Equals(item.Language));
            if (info != null)
            {
                info.ExtensionCodes = item.ExtensionCodes;
                info.Language = item.Language;
                info.Examples = item.Examples;
                info.ExamplesFileName = item.ExamplesFileName;
                info.ExecFileName = item.ExecFileName;
                info.DependCodes = item.DependCodes;
            }
            else
            {
                Languages.Add(item);
            }
        }
    }
}
